package com.yanqu.road.server.cmd.activity.flowerstudy;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.FlowerStudyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.flowerstudy.FlowerStudyModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_FLOWER_STUDY_CHOOSE_POEM,desc = "诗书问答选择题目答案")
public class FlowerStudyChoosePoemCmd extends AbstractCommand {

    private int activityId;
    private int poemId;
    private int choose;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        FlowerStudyProto.FlowerStudyPoemChooseReq chooseReq = FlowerStudyProto.FlowerStudyPoemChooseReq.parseFrom(packet.getBytes());
        activityId = chooseReq.getActivityId();
        poemId = chooseReq.getId();
        choose = chooseReq.getChoose();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(FlowerStudyModule.class).choosePoemAnswer(activityId,poemId,choose);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            FlowerStudyProto.FlowerStudyPoemChooseResp.Builder msg = FlowerStudyProto.FlowerStudyPoemChooseResp.newBuilder();
            msg.setRet(ret);
            player.sendPacket(ClientProtocol.U_FLOWER_STUDY_CHOOSE_POEM,msg);
        }
    }
}
